<template>
	<view class="px-3">
		<uniListItem v-if="loginStatus" :title="item" v-for="(item, index) in list" :key="index"
		@click='open(index)'></uniListItem>
		<uniListItem title="关于社区" @click='about'>
		</uniListItem>
		<uniListItem title="清除缓存" @click='clear'>
			<view slot='right' class="text-light-muted">{{storage}}</view>
		</uniListItem>
		<view class="px-2 py-3" v-if="loginStatus">
			<button class="bg-main text-white" style="border-radius: 50rpx;" type="primary"
			@click="logout"
			>退出登陆</button>
		</view>
	</view>
</template>

<script>
	import uniListItem from '@/components/uni-ui/uni-list-item/uni-list-item.vue';
	import {mapState} from 'vuex'
	export default {
		data() {
			return {
				list: [
					'账号与安全','绑定邮箱','资料编辑','意见反馈'
				],
				storage: 0
			}
		},
		components: {uniListItem},
		onLoad() {
			let res = uni.getStorageInfoSync()
			this.storage = res.currentSize > 1024 ? (res.currentSize/1024 + 'Mb') : (res.currentSize + 'kb')
		},
		computed: {
			...mapState(['loginStatus'])
		},
		methods:{
			clear() {
				uni.showModal({
					content: '是否清除缓存?',
					    success: res => {
							// 清除缓存
							uni.clearStorageSync()
							// 再次获取缓存
							uni.getStorageInfoSync()
					        if (res.confirm) {
					            uni.showToast({
					            	title:'已清除'
					            })
					        } else if (res.cancel) {
					            uni.showToast({
					            	title:'已取消',
									icon:'none'
					            })
					        }
					    }
				})
			},
			about() {
				uni.navigateTo({
					url:'/pages/about/about'
				})
			},
			open(index) {
				if (index == 0) {
					uni.navigateTo({
						url:'/pages/user-password/user-password'
					})
				} else if (index == 1) {
					uni.navigateTo({
						url:'/pages/user-email/user-email'
					})
				} else if (index == 2) {
					uni.navigateTo({
						url:'/pages/user-info/user-info'
					})
				} else {
					uni.navigateTo({
						url:'/pages/user-feedback/user-feedback'
					})
				}
			},
			// 退出登陆
			logout() {
				uni.showModal({
					content:'是否退出登陆?',
					success: (res) => {
						if (res.confirm) {
							this.$store.commit('logout')
							uni.navigateBack({
								delta:1
							})
						}
					}
				})
			}
		}
	}
</script>

<style>
</style>
